<?php

namespace App\Http\Controllers\Wechat;

use App\Http\Controllers\Controller;
use App\Models\ResourceRecom;
use App\Models\ResourceRecomType;
use App\Models\ResourceTotalType;
use App\Validate\ResourceRecomValidate;
use Illuminate\Routing\ResourceRegistrar;


/**
 * 资源大类数据
 */
class ResourceTotalTypeController extends Controller
{
    public $model = null;
    public $typeModel = null;
    public $validate = null;

    public function __construct()
    {
        parent::__construct();

        $this->model = new ResourceTotalType();
    }

    /**
     * 根据资源类型获取资源列表
     * @param big_type_id  资源大类id  未传表示全部
     * @param type_id  资源类型id  未传表示全部
     * @param keywords 关键字搜索
     * @param page 页数    默认第一页
     * @param limit 限制条数   默认 10 条
     */
    public function lists()
    {
        $big_type_id = $this->request->big_type_id;
        $type_id = $this->request->type_id;
        $keywords = $this->request->keywords;
        $limit = $this->request->input('limit', 10);
        $res = $this->model->getResourceTotalTypeDataListByTypeId($big_type_id, $type_id, $keywords, $limit);

        if (empty($res['data'])) {
            return $this->returnApi(203, "暂无数据");
        }

        $res = $this->disPageData($res);
        foreach ($res['data'] as $key => $val) {
            $res['data'][$key]['type_name'] = !empty($val['con_type']) ? $val['con_type']['type_name'] : '';
            $res['data'][$key]['content'] = strip_tags($val['content']);
            $res['data'][$key]['add_time'] = date('Y-m-d', strtotime($val['add_time']));
            unset($res['data'][$key]['type_name']);
        }

        return $this->returnApi(200, "获取成功", true, $res);
    }
}
